package org.idea.qiyu.framework.rocketmq.config.producer;

import org.idea.qiyu.framework.rocketmq.properties.RocketMqProducerProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * mq生产者自动配置类
 *
 * @Author linhao
 * @Date created in 10:08 下午 2021/7/1
 */
@Configuration
@EnableConfigurationProperties(RocketMqProducerProperties.class)
public class MqProducerAutoConfiguration {

    @Resource
    private RocketMqProducerProperties rocketMqProducerProperties;

    @Bean
    @ConditionalOnMissingBean
    public MqProducerFactory producerFactory(){
        MqProducerFactory mqProducerFactory = new MqProducerFactory(rocketMqProducerProperties.getNameSrv(),rocketMqProducerProperties.getGroupName());
        return mqProducerFactory;
    }
}
